﻿

using System;
using System.Collections.Generic;
using System.IO;
using System.ServiceModel;

using WCFModel;
using WCFContract;



namespace WCFService
{
    /// <summary>
    /// MP3文件操作 和Streaming流处理
    /// </summary>
    public class MP3OpeatorService : IMP3Opeator
    {
        #region IMP3Opeator Methons

        public System.Collections.Generic.IList<WCFModel.Music> GetMusicList()
        {
            var list = new List<Music>() 
            {
            new Music(){ Id = 1, Name = "上海滩(江智民).wav", Description= ""},
            new Music(){ Id = 2, Name = "盛夏的果实（刘亮鹭）.wav", Description= ""},
            new Music(){ Id = 3, Name = "特别的爱给特别的你(肖超).wav", Description= ""},
            new Music(){ Id = 4, Name = "错误.wav", Description= ""}
            };
            return list;
        }

        public Stream GetMusicSream(string name)
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\MP3\" + name;
            FileStream stream = null;
            try
            {
                stream = new FileStream(path, FileMode.Open, FileAccess.Read);
            }
            catch (FileNotFoundException ex)
            {
                if (stream != null)
                {
                    stream.Close();
                }
                throw new FaultException<FileNotFoundException>(ex, "未发现文件：" + name + "！");
            }
            return stream;
        }

        #endregion
    }
}
